function ajax(ops){
    ops = ops || {};
    let {data={}, type="get", url, success, error} = ops;
    let str = "";
    for(let i in data){
        str += `${i}=${data[i]}&`;
    }
    if(type === "get"){
        url += "?" + str.slice(0,str.length-1);
    }
    const xhr = new XMLHttpRequest();
    xhr.open(type, url, true);
    xhr.onload = function(){
        if(xhr.status === 200){
            success(xhr.responseText);
        }else{
            error && error(xhr.status);
        }
    }
    if(type === "get"){
        xhr.send();
    }else{
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xhr.send(str);
    }
}